package com.yami.shop.admin.scheduledtasks;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.yami.shop.otherservice.OneLevelDistributionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 一级分销奖金发放
 */
@Component("oneLevelDistributionTask")
public class OneLevelDistributionTask {
    @Autowired
    private OneLevelDistributionService oneLevelDistributionService;

    //每天凌晨五分发放昨天团对长收益
    @Scheduled(cron = "0 5 0 * * ? ")
    public void deactivateExpireMember(){
        //昨天
        DateTime yesterday = DateUtil.yesterday();
        oneLevelDistributionService.grantTeamLeaderReward(yesterday);
    }

    //每天的最后一秒保存当天的可分红用户列表
    @Scheduled(cron = "59 59 23 * * ? ")
    public void saveDayBonusUserToRedis(){
        oneLevelDistributionService.saveDayBonusUserToRedis();
    }

    //每天0点10分0秒,发放每天分红
    @Scheduled(cron = "0 10 0 * * ? ")
    public void dayBonus(){
        //昨天
        DateTime yesterday = DateUtil.yesterday();
        oneLevelDistributionService.grantDayBonus(DateUtil.format(yesterday, "yyyy-MM-dd"));
    }
}
